clear
clear matrix
set mem 2G
set more off

use "NLSYfull.dta"

forvalues x=75/93 {
recode year1change80 (`x'=19`x')
}

forvalues x=75/93 {
recode year2change80 (`x'=19`x')
}
forvalues x=75/93 {
recode year3change80 (`x'=19`x')
}

forvalues x=75/93 {
recode year1change81 (`x'=19`x')
}

forvalues x=75/93 {
recode year2change81 (`x'=19`x')
}
forvalues x=75/93 {
recode year3change81 (`x'=19`x')
}

forvalues x=75/93 {
recode year1change82 (`x'=19`x')
}

forvalues x=75/93 {
recode year2change82 (`x'=19`x')
}
forvalues x=75/93 {
recode year3change82 (`x'=19`x')
}

forvalues x=75/93 {
recode year1change83 (`x'=19`x')
}

forvalues x=75/93 {
recode year2change83 (`x'=19`x')
}
forvalues x=75/93 {
recode year3change83 (`x'=19`x')
}

forvalues x=75/93 {
recode year1change84 (`x'=19`x')
}

forvalues x=75/93 {
recode year2change84 (`x'=19`x')
}
forvalues x=75/93 {
recode year3change84 (`x'=19`x')
}

forvalues x=75/93 {
recode year1change85 (`x'=19`x')
}

forvalues x=75/93 {
recode year2change85 (`x'=19`x')
}
forvalues x=75/93 {
recode year3change85 (`x'=19`x')
}

forvalues x=75/93 {
recode year1change86 (`x'=19`x')
}

forvalues x=75/93 {
recode year2change86 (`x'=19`x')
}
forvalues x=75/93 {
recode year3change86 (`x'=19`x')
}

forvalues x=75/93 {
recode year1change87 (`x'=19`x')
}

forvalues x=75/93 {
recode year2change87 (`x'=19`x')
}
forvalues x=75/93 {
recode year3change87 (`x'=19`x')
}

forvalues x=75/93 {
recode year1change88 (`x'=19`x')
}

forvalues x=75/93 {
recode year2change88 (`x'=19`x')
}
forvalues x=75/93 {
recode year3change88 (`x'=19`x')
}

forvalues x=75/93 {
recode year1change89 (`x'=19`x')
}

forvalues x=75/93 {
recode year2change89 (`x'=19`x')
}
forvalues x=75/93 {
recode year3change89 (`x'=19`x')
}

forvalues x=75/93 {
recode year1change90 (`x'=19`x')
}

forvalues x=75/93 {
recode year2change90 (`x'=19`x')
}
forvalues x=75/93 {
recode year3change90 (`x'=19`x')
}

forvalues x=75/93 {
recode year1change91 (`x'=19`x')
}

forvalues x=75/93 {
recode year2change91 (`x'=19`x')
}
forvalues x=75/93 {
recode year3change91 (`x'=19`x')
}

forvalues x=75/93 {
recode year1change92 (`x'=19`x')
}

forvalues x=75/93 {
recode year2change92 (`x'=19`x')
}
forvalues x=75/93 {
recode year3change92 (`x'=19`x')
}

forvalues x=75/93 {
recode year1change93 (`x'=19`x')
}

forvalues x=75/93 {
recode year2change93 (`x'=19`x')
}
forvalues x=75/93 {
recode year3change93 (`x'=19`x')
}

forvalues x=71/79 {
recode yearrecentmar79 (`x'=19`x')
}

forvalues x=75/79 {
recode yeardivorce79 (`x'=19`x')
}

forvalues x=75/79 {
recode yeardeathspouse79 (`x'=19`x')
}



tabulate marital79
/**month and year of first marriage**/
gen mar1month=monthrecentmar79 if monthrecentmar79>=0 & (marital79==1|marital79==4)
gen mar1year=yearrecentmar79 if yearrecentmar79>=0 & (marital79==1|marital79==4)

forvalues x=80/93 {
replace mar1month=month1change`x' if status1`x'==1 & mar1month==.
replace mar1year=year1change`x' if status1`x'==1 & mar1year==.

replace mar1month=month2change`x' if status2`x'==1 & mar1month==.
replace mar1year=year2change`x' if status2`x'==1 & mar1year==.

replace mar1month=month3change`x' if status3`x'==1 & mar1month==.
replace mar1year=year3change`x' if status3`x'==1 & mar1year==.
}


replace mar1month=month1change94mar if status194==1 & mar1month==.
replace mar1year=year1change94mar if status194==1 & mar1year==.

forvalues x=96(2)98 {
replace mar1month=month1change`x' if type1change`x'==1 & mar1month==.
replace mar1year=year1change`x' if type1change`x'==1 & mar1year==.

replace mar1month=month2change`x' if type2change`x'==1 & mar1month==.
replace mar1year=year2change`x' if type2change`x'==1 & mar1year==.

replace mar1month=month3change`x' if type3change`x'==1 & mar1month==.
replace mar1year=year3change`x' if type3change`x'==1 & mar1year==.
}


replace mar1month=month1change00 if type1change00==1 & mar1month==.
replace mar1year=year1change00 if type1change00==1 & mar1year==.

replace mar1month=month2change00 if type2change00==1 & mar1month==.
replace mar1year=year2change00 if type2change00==1 & mar1year==.

replace mar1month=month3change00 if type3change00==1 & mar1month==.
replace mar1year=year3change00 if type3change00==1 & mar1year==.

replace mar1month=month1change02 if type1change02==1 & mar1month==.
replace mar1year=year1change02 if type1change02==1 & mar1year==.

replace mar1month=month2change02 if type2change02==1 & mar1month==.
replace mar1year=year2change02 if type2change02==1 & mar1year==.

replace mar1month=month3change02 if type3change02==1 & mar1month==.
replace mar1year=year3change02 if type3change02==1 & mar1year==.

replace mar1month=month1change04 if type1change04==1 & mar1month==.
replace mar1year=year1change04 if type1change04==1 & mar1year==.

replace mar1month=month2change04 if type2change04==1 & mar1month==.
replace mar1year=year2change04 if type2change04==1 & mar1year==.

replace mar1month=month3change04 if type3change04==1 & mar1month==.
replace mar1year=year3change04 if type3change04==1 & mar1year==.

replace mar1month=month1change06 if type1change06==1 & mar1month==.
replace mar1year=year1change06 if type1change06==1 & mar1year==.

replace mar1month=month2change06 if type2change06==1 & mar1month==.
replace mar1year=year2change06 if type2change06==1 & mar1year==.

replace mar1month=month3change06 if type3change06==1 & mar1month==.
replace mar1year=year3change06 if type3change06==1 & mar1year==.

replace mar1month=month1change08 if type1change08==1 & mar1month==.
replace mar1year=year1change08 if type1change08==1 & mar1year==.

replace mar1month=month2change08 if type2change08==1 & mar1month==.
replace mar1year=year2change08 if type2change08==1 & mar1year==.

replace mar1month=month3change08 if type3change08==1 & mar1month==.
replace mar1year=year3change08 if type3change08==1 & mar1year==.

/***age of spouse 1**/

/**month of birth**/
gen monthspouse1=.


forvalues x=79/94 {
replace monthspouse1=month_spouse`x' if month_spouse`x'>0 & monthspouse1==.
}
forvalues x=96(2)98 {
replace monthspouse1=month_spouse`x' if month_spouse`x'>0 & monthspouse1==.
}

replace monthspouse1=month_spouse00 if month_spouse00>0 & monthspouse1==.
replace monthspouse1=month_spouse02 if month_spouse02>0 & monthspouse1==.
replace monthspouse1=month_spouse04 if month_spouse04>0 & monthspouse1==.
replace monthspouse1=month_spouse06 if month_spouse06>0 & monthspouse1==.
replace monthspouse1=month_spouse08 if month_spouse08>0 & monthspouse1==.

/**year of birth of spouse**/
gen yearspouse1=.
rename year_pouse79 year_spouse79

forvalues x=79/94 {
replace yearspouse1=year_spouse`x' if year_spouse`x'>0 & yearspouse1==.
}
forvalues x=96(2)98 {
replace yearspouse1=year_spouse`x' if year_spouse`x'>0 & yearspouse1==.
}

replace yearspouse1=year_spouse00 if year_spouse00>0 & yearspouse1==.
replace yearspouse1=year_spouse02 if year_spouse02>0 & yearspouse1==.
replace yearspouse1=year_spouse04 if year_spouse04>0 & yearspouse1==.
replace yearspouse1=year_spouse06 if year_spouse06>0 & yearspouse1==.
replace yearspouse1=year_spouse08 if year_spouse08>0 & yearspouse1==.


forvalues x=57/64 {
recode yearbirth (`x'=19`x')
}

forvalues x=14/75 {
recode yearspouse1 (`x'=19`x')
}



gen ageR=ym(yearbirth,monthbirth)
format ageR %tm

gen agespouse1=ym(yearspouse1,monthspouse1)


format agespouse1 %tm

/**education variables**/

gen educ=max(educ79,educ80,educ81,educ82,educ83,educ84,educ85,educ86,educ87,educ88,educ89,educ90,educ91,educ92,educ93,educ94,educ96, ///
educ98,educ00,educ02,educ04,educ06,educ08)

drop if mar1year<0
drop if mar1year==.
drop if yearspouse1==.

keep CASEID yearbirth RACE SEX AFQT_1 mar1year monthspouse1 yearspouse1 educ SAMPWEIGHT79

rename SAMPWEIGHT79 wgt

gen difagemar1=yearbirth-yearspouse1

drop yearspouse1 monthspouse1


save "CouplesNLSY.dta", replace





